package com.handle;

import com.message.ping.PingMessage;
import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.timeout.IdleState;
import io.netty.handler.timeout.IdleStateEvent;
import lombok.extern.slf4j.Slf4j;

/**
 * @author linyu.dai
 * @project rpc
 * @description
 * @creat 2022/11/29 10:44:30
 */
@Slf4j
public class IdleStateEventHandle extends ChannelDuplexHandler {

    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
        IdleStateEvent event = (IdleStateEvent) evt;
        if(event.state() == IdleState.WRITER_IDLE){
//            log.info("3秒没有写数据  发送心跳包");
            ctx.channel().writeAndFlush(new PingMessage());
        }
    }
}
